﻿#ifndef GraphEdgeTypes_h__
#define GraphEdgeTypes_h__

/********************************************************************
	创建于:		2011/03/17
	创建于:		17:3:2011   22:42
	基本文件:	GraphEdgeTypes
	文件扩展:	h
	作者:		王凯
	
	目的:		该代码主要思想来自于Mat先生的GraphEdgeTypes
				此代码提供对图算法中边类型表示的支持
*********************************************************************/
#include <ostream>
#include "NodeTypeEnumerations.h"

class GraphEdge
{
protected:
	//边连接的两个点，有效值应为>=0
	int m_iTo;
	int m_iFrom;

	//权值
	double m_dCost;
public:
	
	//无参数的构造
	GraphEdge():m_dCost(1.0),
		m_iTo(invalid_node_index),
		m_iFrom(invalid_node_index){}
	//省缺权值的构造
	GraphEdge(int from, int to):m_dCost(1.0),
		m_iFrom(from), m_iTo(to){}
	//无省缺的构造
	GraphEdge(int from, int to , double cost):
		m_dCost(cost),
		m_iFrom(from),
		m_iTo(to){}

	virtual	~GraphEdge(){}

	int To()const{	return m_iTo;}
	void SetTo(const int newto){	m_iTo = newto;}

	int From()const{ return m_iFrom;}
	void SetFrom(const int newFrom){	m_iFrom = newFrom;}

	double Cost()const{	return m_dCost;}
	void SetCost(const double newCost){	m_dCost = newCost;}

	//重载==运算符
	bool operator==(const GraphEdge& rhs)
	{
		return this->m_dCost == rhs.m_dCost &&
			this->m_iFrom == rhs.m_iFrom &&
			this->m_iTo == rhs.m_iTo;
	}
	//重载！=运算符
	bool operator!=(const GraphEdge& rhs)
	{
		return (*this == rhs);
	}
	//重载输出运算符 
	friend std::ostream& operator<<(std::ostream& os,const GraphEdge& e)
	{
		os<<"From:"<<e.m_iFrom<<" To:"<<e.m_iTo<<" Cost:"<<e.m_dCost<<std::endl;
		return os;
	}
};

class NavGraphEdge :public GraphEdge
{
protected:
	int   m_iFlags;

	//if this edge intersects with an object (such as a door or lift), then
	//this is that object's ID. 
	int  m_iIDofIntersectingEntity;
public:
	//增加图的灵活性，以表示各种地形
	enum 
	{
		normal            = 0,
		swim              = 1 << 0,
		crawl             = 1 << 1,
		creep             = 1 << 3,
		jump              = 1 << 3,
		fly               = 1 << 4,
		grapple           = 1 << 5,
		goes_through_door = 1 << 6
	};

	//带参数的构造
	NavGraphEdge(int from, int to, double cost,
		int flags = 1,
		int id = -1):
		GraphEdge(from, to, cost),
		m_iFlags(flags),
		m_iIDofIntersectingEntity(id){}

	~NavGraphEdge(){}

	int Flages()const{ return m_iFlags;}
	void SetFlages(int flage){ m_iFlags = flage;}

	int  IDofIntersectingEntity()const{return m_iIDofIntersectingEntity;}
	void SetIDofIntersectingEntity(int id){m_iIDofIntersectingEntity = id;}

	//重载输出运算符
	friend std::ostream& operator<<(std::ostream& os, const NavGraphEdge& ne)
	{
		os<<"From:"<<ne.m_iFrom<<" To:"<<ne.m_iTo<<" Cost:"<<ne.m_dCost<<
			" Flages:"<<ne.m_iFlags<<" ID:"<<ne.m_iIDofIntersectingEntity<<std::endl;
		return os;
	}
};

#endif // GraphEdgeTypes_h__